<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>创建合同订单</title>
    <%@ include file="/WEB-INF/views/include/head.jsp"%>
    <script src="${ctxStatic}/js/jquery-1.9.1.min.js"></script>
    <script src="${ctxStatic}/js/DateTimePicker.js"></script>
    <script src="${ctxStatic}/js/layer.js"></script>
    <script src="${ctxStatic}/js/style.js"></script>
    <script src="${ctxStatic}/dateCalendar/WdatePicker.js"></script>
    <link rel="stylesheet" href="${ctxStatic}/css/common.css">
    <link rel="stylesheet" href="${ctxStatic}/css/layerSm.css">
    <script type="text/javascript">
    $(document).ready(function(){
    	var form = $("#inputForm");  
        form.validate();//验证指定的表单
    	$("#userGroupID").select2();
   		$("#okButton").click(function(){
    		if (form.valid()) {//如果表单验证成功，则进行提交。  
    		$("#showHtml").addClass("showHtml");
            $("#okHead").show();
            $("#createHead").hide();  
            $("#advanceDueDate").removeClass("laydate-icon");
            $("#appDate").removeClass("laydate-icon");
            return false;
          	}
     	});
    });
    
    /* 保存创建/编辑信息 */
    function saveForm(){
    	var params = $("#inputForm").serialize();
    	$.post("${ctx}/produce/plan/save",params,function(result){
    		/* 弹出提示框,刷新父页面,关闭当前页面 */
    		tipParent(result.message);
    		 window.parent.frames[0].searchListForm();
    		closeWin();
    	},'json');
    	
    }
    /* 动态计算日期  */
    function timeFun(t){
   		var period = $("#planPeriod").val();
   		var beginDate = $("#planBeginDate").val();
   		var endDate = $("#planEndDate").val();
   		//计划生产周期    投产日期
   		if (t == "planPeriod" || t == "planBeginDate") {
			if (beginDate != "" && period != "") {
				if (parseFloat(period) >= parseFloat(1)) {
		   			period = parseFloat(period) - parseFloat(1);
				}else{
					period = 0;
				}
				var nd = new Date(beginDate);
			   	nd = nd.valueOf();
			   	nd = nd + parseFloat(period) * 24 * 60 * 60 * 1000;
			   	nd = new Date(nd);
			   	var y = nd.getFullYear();
			   	var m = nd.getMonth()+1;
			   	var d = nd.getDate();
			   	if(m <= 9) m = "0"+m;
			   	if(d <= 9) d = "0"+d; 
			   	var cdate = y+"-"+m+"-"+d;
			   	$("#planEndDate").val(cdate);
			}else{
				return;
			}
		//完成日期
		}else if (t == "planEndDate") {
			if (beginDate != "") {
				var nbd = new Date(beginDate);
				var ned = new Date(endDate);
				nbd = nbd.valueOf();
				ned = ned.valueOf();
			   	$("#planPeriod").val((ned-nbd)/(24 * 60 * 60 * 1000)+1);
			}else{
				return;
			}
		}
    }
    </script>
    <style type="text/css">
    .linkBox{
	color:#0a6dca;
	cursor:pointer;
	text-decoration:underline;
	}
	.showHtml input{
	border:none;
	background-color:inherit;
	color:#333;
	}
    </style>
</head>
<form id="inputForm">
<body>   

<div id="createHead" class="layerHeader clearfix">
<c:choose>
	   <c:when test="${purchaseAdvance.id!=null && purchaseAdvance.id!=''}">
	    <!-- 编辑 --> 
			<p class="headerTitle">订单计划排期</p>
       </c:when>
       <c:otherwise>
        <!-- 创建 --> 
            <p class="headerTitle">订单计划排期</p>
       </c:otherwise>
    </c:choose>
	
    <div class="headerButton clearfix">
        <!-- 确定 -->
        <button type="button" id="okButton"><spring:message code="purchaseAdvance_edit_ok"/></button>
        <!-- 取消 -->
        <button type="button" onclick="closeWin()"><spring:message code="purchaseAdvance_edit_cancle"/></button>
    </div>
</div>
<!-- 确认画面头部 -->
<div id="okHead" class="layerHeader clearfix" style="display: none;">	      
             <p class="headerTitle">订单计划排期</p>    
    <div class="headerButton clearfix">
	    <!-- 编辑 保存 --> 
			<button type="button" onclick="saveForm();"><spring:message code="common_save" /></button>
        <!-- 取消 -->
          <button type="button" onclick="closeWin()"><spring:message code="purchaseAdvance_edit_cancle"/></button>
    </div>
</div>

<div id="showHtml" class="smOrderBox">
		
        <input type="hidden" id="id" name="id" value="${producePlan.id }">
    <div class="items clearfix">
        <div class="col-50 clearfix haveToBox">
        <!-- 客户 -->
            <p class="tit" style="width: 80px">客&ensp;&ensp;&ensp;&ensp;户</p>
            <input type="hidden" id="ognizationID" name="ognizationID" value="${producePlan.ognizationID }">
            <input type="text" id="ognizationName" name="ognizationName" value="${producePlan.ognizationName }" readonly="readonly" data-rule-required="true" data-msg-required="<spring:message code="purchaseAdvance_error_msg_contractMaterialNO"/>">
            <button type="button" onclick="popup('900px','584px','${ctx}/purchase/contract/ognizationList?ognizationFlag=5&frameFlg=3')"><spring:message code="purchaseAdvance_edit_select"/></button>
            <p class="haveTo">*</p>
        </div>
        <div class="col-50 clearfix haveToBox">
        <!-- 款式名称 -->
            <p class="tit" style="width: 80px">款式名称</p>
             <input type="text" id="styleName" name="styleName" value="${producePlan.styleName }">
             <p class="haveTo">*</p>
        </div>
        
    </div>
    <div class="items clearfix">
        <div class="col-50 clearfix haveToBox">
        <!-- 计划生产班组  -->
            <p class="tit" style="width: 80px">计划生产班组</p>
            <select  name="userGroupID" id="userGroupID" style="width: 150px">
                   <option value=""><spring:message code="order_please_choose"/></option>
                   <c:forEach items="${groupList}" var="group">
                       <option value="${group.userGroupID}" <c:if test="${producePlan.userGroupID eq group.userGroupID }">selected="selected"</c:if>>${group.groupName}</option>
                   </c:forEach>
            </select>
            <p class="haveTo">*</p>
        </div>
        <div class="col-50 clearfix haveToBox">
        <!-- 计划订单数量  -->
            <p class="tit" style="width: 80px">计划订单数量</p>
             <input type="tel" id="planQuantity" name="planQuantity" value="${producePlan.planQuantity }">
             <p class="haveTo">*</p>
        </div>
    </div>
    <div class="items clearfix" >        	
                <div class="col-50 clearfix haveToBox">
                <!-- 单人生产效率 -->
                    <p class="tit" style="width: 80px">单人生产效率</p>
                    <input type="tel" id="planEfficiency" name="planEfficiency" value="${producePlan.planEfficiency }">&ensp;(件/人)
                    <p class="haveTo">*</p>
                </div>
                
                <div class="col-50 clearfix haveToBox">
                <!-- 投产人数  -->
                    <p class="tit" style="width: 80px">投产人数</p>
                    <input type="tel" id="planNumber" name="planNumber" value="${producePlan.planNumber }">&ensp;(人)
                	<p class="haveTo">*</p>
                </div>
            </div>
    
            <div class="items clearfix haveToBox">        	
                <div class="col-50 clearfix">
                <!-- 计划生产周期  -->
                    <p class="tit" style="width: 80px">计划生产周期</p>
                    <input type="tel" id="planPeriod" name="planPeriod" onchange="timeFun(this.id);" value="${producePlan.planPeriod }" data-rule-required="true" data-msg-required="<spring:message code="purchaseAdvance_error_msg_advanceAmount"/>">&ensp;(天)
           			<p class="haveTo">*</p>
                </div>
                <div class="col-50 clearfix">
                <!-- 计划交货日期 -->
                    <p class="tit" style="width: 80px">计划交货日期</p>
                    <input type="text" onblur="CheckDate(this);" 
								id="planDeliveryDate" name="planDeliveryDate" value="<fmt:formatDate value="${producePlan.planDeliveryDate }" pattern="yyyy-MM-dd" />">
                </div>
            </div>
            <div class="items clearfix" >        	
                <div class="col-50 clearfix haveToBox">
                <!-- 计划开始日期 -->
                    <p class="tit" style="width: 80px">计划开始日期</p>
                    <input type="text" onblur="if(CheckDate(this)==true) timeFun(this.id);" 
								id="planBeginDate" name="planBeginDate" value="<fmt:formatDate value="${producePlan.planBeginDate }" pattern="yyyy-MM-dd" />" data-rule-required="true" data-msg-required="<spring:message code="purchaseAdvance_error_msg_advanceDueDate"/>">
                    <p class="haveTo">*</p>
                </div>
                
                <div class="col-50 clearfix haveToBox">
                <!-- 计划清活日期 -->
                    <p class="tit" style="width: 80px">计划清活日期</p>
                    <input type="text" onblur="if(CheckDate(this)==true) timeFun(this.id);" 
								id="planEndDate" name="planEndDate" value="<fmt:formatDate value="${producePlan.planEndDate }" pattern="yyyy-MM-dd" />" data-rule-required="true" data-msg-required="<spring:message code="purchaseAdvance_error_msg_advanceDueDate"/>">
                    <p class="haveTo">*</p>
                </div>
            </div>
            <div class="items clearfix showHtml">
                
        		<div class="clearfix">
        		<!-- 备注 -->
            		<p class="tit" style="width: 80px">备&ensp;&ensp;&ensp;&ensp;注</p>
            		<textarea name="remarks" style="width:630px;height: 60px">${producePlan.remarks }</textarea>
        		</div>
    	</div>
</div>
</form>
<script>
	window.onload = function(){
	$('.tableScrollSm').css('height','325px')
	$('td input').each(function(){
		var tdH = $(this).parents('td').height()
		$(this).css('height',tdH)
		})
	}
	var tableW = $('.tableHead').outerWidth();
	$('.tableScroll').css('width',tableW + 18 + 'px')

</script>
</body>
</html>
